/*******************************************************************************
 * Copyright (c) 2002 Boris Pruessmann and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Common Public License v0.5 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.dialogs;

import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;

/**
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
public class StatusComposite extends Composite implements PaintListener, DisposeListener {

  /** Stores the border color */
  private Color borderColor;

  /**
   * Constructor for StatusComposite.
   * 
   * @param parent the parent composite.
   * @param style the style
   */
  public StatusComposite(Composite parent, int style) {
    super(parent, style);

    addDisposeListener(this);
    addPaintListener(this);

    borderColor = new Color(parent.getDisplay(), new RGB(157, 157, 161));
  }

  /** @see PaintListener#paintControl(PaintEvent) */
  public void paintControl(PaintEvent e) {
    GC gc = e.gc;

    Rectangle bounds = getBounds();

    Color oldFg = gc.getForeground();
    gc.setForeground(borderColor);

    gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);


    gc.setForeground(oldFg);
  }

  /** @see DisposeListener#widgetDisposed(DisposeEvent) */
  public void widgetDisposed(DisposeEvent e) {
    if (borderColor != null) {
      borderColor.dispose();
    }
  }
}
